#include<cstdio>
#include<queue>
#include<algorithm>
#include<cstring>
using namespace std;
const int MAXN=1e3+10,MAXM=1e5+10,INF=0x7fffffff;
int n,m,s,t,k,head[MAXN],cnt,dis[MAXN];
bool vis[MAXN];
struct edge
{
	int u,v,val,next;
}e[MAXM];
struct point
{
	int o,g,h;
	bool operator <(const point a)const
	{
		return g+h>a.g+a.h;
	}
};
void addedge(int a,int b,int c)
{
	e[cnt]=(edge){a,b,c,head[a]};
	head[a]=cnt++;
	return;
}
void rev()
{
	memset(head,-1,sizeof(head));
	for(int i=0;i<m;++i)
	{
		int t=e[i].u;e[i].u=e[i].v;e[i].v=t;
		e[i].next=head[e[i].u];
		head[e[i].u]=i;
	}
	return;
}
void SPFA()
{
	for(int i=1;i<=n;++i)dis[i]=INF;
	dis[t]=0;
	vis[t]=true;
	queue<int>q;
	q.push(t);
	while(!q.empty())
	{
		int u=q.front();
		q.pop();
		for(int i=head[u];~i;i=e[i].next)
		{
			int v=e[i].v;
			if(dis[u]+e[i].val<dis[v])
			{
				dis[v]=dis[u]+e[i].val;
				if(!vis[v])
				{
					q.push(v);
					vis[v]=true;
				}
			}
		}
		vis[u]=false;
	}
	return;
}
int	A_star()
{
	priority_queue<point>q;
	cnt=0;
	q.push((point){s,0,dis[s]});
	while(!q.empty())
	{
		point u=q.top();
		q.pop();
		if(u.o==t)++cnt;
		if(cnt==k)return u.g;
		for(int i=head[u.o];~i;i=e[i].next)
			q.push((point){e[i].v,u.g+e[i].val,dis[e[i].v]});
	}
	return -1;
}
int main()
{
	memset(head,-1,sizeof(head));
	scanf("%d%d",&n,&m);
	for(int i=1;i<=m;++i)
	{
		int x,y,z;
		scanf("%d%d%d",&x,&y,&z);
		addedge(y,x,z);
	}
	scanf("%d%d%d",&s,&t,&k);
	if(s==t)++k;
	SPFA();
	if(dis[s]==INF)
	{
		printf("-1\n");
		return 0;
	}
	rev();
	printf("%d\n",A_star());
	return 0;
}
